import { useStore } from 'vuex'
import { PLAY_KEY } from '@/js/constant'
import { save } from '@/js/array-store'

export default function usePlayHistory () {
  const store = useStore()

  function savePlayHistory (song) {
    const songs = save(song, PLAY_KEY, (item) => {
      return item.id === song.id
    })
    if (songs.length > 200) {
      songs.pop()
    }
    store.commit('setPlayHistory', songs)
  }
  return {
    savePlayHistory
  }
}
